
// 雨燕直播, 播放窗口全屏
var yuyanDomains = ["www.yuyanlive.com/room/", "www.yuyan.live/room/", "yuyantv.tv/room/", "yuyanzhibo.cn", "yuyanzhibo.cc"];
var isYuyan = false;
for(domainIdx in yuyanDomains) {
	if(-1 != window.location.href.indexOf(yuyanDomains[domainIdx])) {
		isYuyan = true;
		break;
	}
}
if(isYuyan) {
	console.log("雨燕直播, 播放窗口全屏");

	InsertZoomInBtn('.live-room .inner .top-left-block .text-title', function() {
		$('.header-wrapper').remove();
		$('.live-room .inner .chat').remove();
		$('.liveRoom-wrapper > .appoinment-list.inner').remove();
		$('.liveRoom-wrapper > .category.inner').remove();
		$('.liveRoom-wrapper > .footer-wrapper').remove();
		$('.liveRoom-wrapper .bottom-block').remove();

		$('.liveRoom-wrapper').css('min-width', '0');
		$('.liveRoom-wrapper > .live-room').css('height', '1080px').css('padding-top', 0);
		$('.liveRoom-wrapper > .live-room >.inner').css('width', '100%!important');
		$('.liveRoom-wrapper > .live-room >.inner').attr('style', 'width: 100%!important;');
		$('.liveRoom-wrapper > .live-room >.inner > .media').css('width', '100%');
		$('.liveRoom-wrapper > .live-room >.inner > .media > .center-block').css('height', '100%');
	});

	/*
	if(confirm('播放窗口切换成全屏？')){
		$('.header-wrapper').remove();
		$('.live-room .inner .chat').remove();
		$('.liveRoom-wrapper > .appoinment-list.inner').remove();
		$('.liveRoom-wrapper > .category.inner').remove();
		$('.liveRoom-wrapper > .footer-wrapper').remove();
		$('.liveRoom-wrapper .bottom-block').remove();

		$('.liveRoom-wrapper').css('min-width', '0');
		$('.liveRoom-wrapper > .live-room').css('height', '1080px').css('padding-top', 0);
		$('.liveRoom-wrapper > .live-room >.inner').css('width', '100%!important');
		$('.liveRoom-wrapper > .live-room >.inner').attr('style', 'width: 100%!important;');
		$('.liveRoom-wrapper > .live-room >.inner > .media').css('width', '100%');
		$('.liveRoom-wrapper > .live-room >.inner > .media > .center-block').css('height', '100%');
	}
	*/
}

// 咪咕视频放大到窗口大小
if('m.miguvideo.com' == window.location.host || 'www.miguvideo.com' == window.location.host) {
	console.log("咪咕视频");

	var $app = $('#app');
	var findVideoTimer = setInterval(function() {
		var $video = $app.find('.player-01');
		var $header = $app.find('.header');
		if(0 == $video.length || 0 == $header.length) {
			// console.log("播放器未加载完");
			return;
		}

		clearInterval(findVideoTimer);
		// console.log("找到播放器");

		$app.data('width-old', $app.width()).data('is-zoom-in', false);
		$video.data('height-old', $video.height());

		InsertZoomInBtn($header, function() {
			var isZoomIn = $app.data('is-zoom-in');
			var appWidth = '';
			var videoHeight = '';
			if(isZoomIn) {
				$app.width($app.data('width-old'));
				$video.height($video.data('height-old'));
				$app.data('is-zoom-in', false);
			} else {
				$app.width('100%');
				var nowAppWidth = $app.width();
				$video.height(nowAppWidth * 0.5625);	// 视频宽高比
				$app.data('is-zoom-in', true);
			}
		});

		$header.remove();
		$app.find('.header-box').height('100%');
	}, 200);
}

// 袋鼠直播放大到窗口大小
if(-1 != window.location.host.search(/dszb\d+.com/i)) {
	console.log("袋鼠直播");
	$(function() {
		setInterval(function() {
			$('#neiyeTabs').hide();
			var $mainWrap = $('.mainWrap.fixedLive');
			$mainWrap.css('padding', 0).css('max-width', "100vw");
			$mainWrap.find('iframe#videoiframe').height('100vh').css('max-height', "100vh");
			var dp_video = document.getElementById('videoiframe')
				.contentWindow.document.getElementById('dp_video');
			$(dp_video).height('100vh');
			$('.pc_appkhd').remove();
			$('.pc_code_view').remove();
			$('.shuoqiudiAPP').remove();
		}, 3000);
	});
}

// 34433体育直播放大到窗口大小
if('34433ty.com' == window.location.host) {
	console.log("34433体育直播");

	$(function() {
		// 上方比赛名
		$('.container .zbgame').remove();
		// 右边广告
		$('.container .zbright').remove();
		// 底部广告
		const $footerNav = $('.container .zbnav');
		$footerNav.prev().prev().remove();
		$footerNav.prev().remove();
		$footerNav.remove();
		$('.container .main .daohang').css('display', 'contents');

		InsertZoomInBtn('.container .main .daohang', function() {
			$('.container .main').width('100%');
			const $videoContainer = $('.container .main .zbleft');
			const oldWidth = $videoContainer.width();
			const oldHeight = $videoContainer.height();
			$videoContainer.data('width-old', oldWidth)
				.data('height-old', oldHeight)
				.data('is-zoom-in', false);

			$videoContainer.width('100%');
			$videoContainer.find('iframe').width('100%');

			const zoomInWidth = $videoContainer.width();
			$videoContainer.find('iframe').height(zoomInWidth * (oldHeight / oldWidth));
		});
	});
}

//  快体育直播(kuaizhibo.live)放大到窗口大小
if('123kzb.net' == window.location.host || 'kzb0101.com' == window.location.host) {
	console.log("快体育 kuaizhibo.live");

	$(function() {
		// 头部区
		$('#app .head').remove();
		InsertZoomInBtn('#app .mainWrap', function() {
			$('#app .mainWrap').css('max-width', 'none').css('padding', '0');
			$('#fixedPlayers').css('margin-top', '0');

			const $videoContainer = $('#videoiframe');
			const oldWidth = $videoContainer.width();
			const oldHeight = $videoContainer.height();
			$videoContainer.data('width-old', oldWidth)
				.data('height-old', oldHeight)
				.data('is-zoom-in', false);

			// 右边聊天窗口
			$('#PlayersTabs_w').remove();
			setTimeout(function() {
				const zoomInWidth = $videoContainer.width();
				$videoContainer.css('max-height', 'none');
				// 因为视频窗口还包括一些其它内容, 会占用高度, 所以放大时乘以一个近似的系数来拉高, 否则会有左右黑边
				const videoHeight = zoomInWidth * (oldHeight / oldWidth) * 1.2;
				$videoContainer.height(videoHeight);
				// iframe容器的高度也要调整
				$("#is_showShop").height(videoHeight + 50);
			}, 1000);
		});
	});
}

// 直播吧视频放大到窗口大小
if('www.zhibo8.cc' == window.location.host || 'www.zhibo8.com' == window.location.host) {
	console.log("直播吧视频放大到窗口大小");

	var setControlsPanel = function() {
		console.log('setControlsPanel');
		$('#main .box .player-box .video-player .vcp-player .vcp-controls-panel').css('bottom', '-50px');
	}

	$('.pop-autoapp, #popautoapp').remove();
	var $video_box = $('.video_box');
	$video_box.mouseenter(setControlsPanel);
	if($video_box.length > 0) {
		var heightRate = $('#main .thumb_img').width() / $('#main .thumb_img').height();

		InsertZoomInBtn('.title', function() {
			// https://www.zhibo8.cc/zuqiu/2020/1114-177d5a1-svideo.htm 进这里调试
			// 执行两次是不想设置完宽度再获取宽度, 然后才能算出高度, 很麻烦, 偷个懒, 直接再执行一次就行了
			for(var loop = 0; loop < 2; ++loop) {
				var videoWidth = $('#main .box .player-box .video-player .vcp-player video').width();
				var videoHeight = videoWidth / heightRate;
				$('.container').width('100%');
				$('#main').width('100%');
				$('#main .box').width('100%');
				$('#main .box .player-box').width('100%').height(videoHeight);
				$('#main .box .player-box .video-player').width('100%').height(videoHeight);
				$('#main .box .player-box .video-player .vcp-player').width('100%').height(videoHeight);
				$('#main .box .player-box .video-player .vcp-player video').width('100%').height(videoHeight);
				setControlsPanel();
			}
		});
	}
}

// 美剧天堂删除广告
// if('www.meijutt.tv' == window.location.host) {
if(-1 != window.location.host.indexOf(".meijutt.")) {
	console.log("美剧天堂删除广告");

	$('.widget-weixin').remove();
	$(".warp .position").prev().remove();
	$(".warp .list").prev().remove();
	$(".warp .list0").next().remove();
	$(".warp .play_top").next().remove();
	setTimeout(function() {
		$('#HMRichBox').remove();
		$("#coupletright").remove();
		$("#coupletleft").remove();
		$('.btnclose.tooltipstered').parent('div').remove();	// 找到广告上的关闭按钮, 然后删除它父级DIV
		$('#hbidbox').parent('divz').remove();	// 找到广告上的关闭按钮, 然后删除它父级DIV

		$wholeWinAd = $("a:last");	// 全屏广告层
		if($wholeWinAd.css('position') == 'fixed') {
			$wholeWinAd.remove();
		}
	}, 3000);
}

// 百度网盘看视频时整理样式
if(-1 != window.location.href.indexOf("pan.baidu.com/play/video")) {
	console.log("百度网盘看视频时整理样式");

	InsertBtn('.video-title .video-title-left', function() {
		var videoWrapOuter = $(".video-wrap-outer");
		var videoWrapOuterHeight = videoWrapOuter.height()
		videoWrapOuter.height(videoWrapOuterHeight + 36);
		$(".video-wrap").height(videoWrapOuterHeight + 36);

		// 因为 shadow-root 为关闭, 所以无法操作
		return;

		var videoRoot = document.querySelector("#video-root");
		var shadow = videoRoot.attachShadow({mode: 'open'});
		var newStyle = document.createElement("style");
		var controlCss = document.createTextNode("#html5player.visiblevideo{height: " + videoWrapOuterHeight + "px;} .video-js .vjs-play-control {bottom: -36px;}");
		newStyle.appendChild(controlCss);
		shadow.appendChild(newStyle);
	}, '视频样式');
}

// 美剧天堂视频放大到窗口大小
/*
if(-1 != window.location.href.indexOf("www.meijutt.tv/video/")) {
	console.log("美剧天堂视频放大到窗口大小");

	InsertZoomInBtn('.play_menu', function() {
		$('.warp').width('100%');
		$('.warp .kp_flash_box').height('800px');
		$('.warp .kp_flash_box .kp_flashbox_wrap').width('100%');
		$('iframe#player-frame').height('800px');
		// $('iframe#player-frame #divbox iframe').height('800px');
		// TODO: iframe 没有JQ, 可能需要原生JS操作
		$('body > div:nth-child(2) > iframe').height('800px');
	});
} */

// 说球帝
if('www.gxyj88.com/' == window.location.host) {
	console.log("说球帝");

	$('#neiyeTabs').remove();
	$('#app .mainWrap').css("padding", "0");
}

// 阿里云盘
if(-1 != window.location.href.indexOf("www.aliyundrive.com/drive")) {
	console.log("阿里云盘");

	$(function() {
		setInterval(function() {
			var video = $('div[class^="video-previewer--"]');
			console.log(video);
			if(video != null) {
				// video.setAttribute('style', 'padding: 0');
				$('div[class^="video-previewer--"]').css('padding-top', '0');
				$('div[class^="video-previewer--"]').css('padding-left', '0');
				$('div[class^="video-previewer--"]').css('padding-right', '0');
				$('div[class^="video-previewer--"]').css('padding-bottom', '80px');
				$('div[class^="video-player-"]').css('opacity', '0.5');
				$('div[class^="toolbar-wrapper--"]').css('opacity', '0.2');
				$('div[class^="toolbar-wrapper--"]').css('background', 'rgba(115, 115, 117, 0.42)');
			}
		}, 3000);
	});
}
